#!/usr/bin/make -f

# Copyright 2018-present RebirthDB
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# This file incorporates work covered by the following copyright:
#
#     Copyright 2010-present, The Linux Foundation, portions copyright Google and
#     others and used with permission or subject to their respective license
#     agreements.
#
#     Licensed under the Apache License, Version 2.0 (the "License");
#     you may not use this file except in compliance with the License.
#     You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
#     Copyright 2013 hello-debhelper project (used according to license) with modifications by RebirthDB

package?=$(shell cat debian/control | grep '^Source:' | awk '{ printf "%s" , $$2 }')

PVERSION?=$(shell cat debian/rebirthdb.version)

DEBUG?=0

clean:
	dh_clean
	if [ -e build ] ; then rm -rf build ; fi ;

install:
	dh_clean
	dh_installdirs
	$(MAKE) DEBUG=$(DEBUG) DESTDIR=$(CURDIR)/debian/$(package) PVERSION=$(PVERSION) STRIP_ON_INSTALL=0 -j`nproc` install

build:
	./configure
	# VERBOSE was previously set to 1. Set it to 0 so the build process
	# would print the logs during the binary build of rebirthdb. Failure
	# to do this caused travis to terminate the packaging process.thinking
	# it had become unresponsive.
	#
	# The displayed COUNTDOWN_TOTAL is wrong. Unable to figure out why, just yet.
	$(MAKE) DEBUG=$(DEBUG) PVERSION=$(PVERSION) VERBOSE=0 SYMBOLS=1 -j`nproc`
	touch build

binary-indep: install

binary-arch: install
	dh_installdocs -a
	dh_installchangelogs -a
	dh_strip --dbg-package=$(package)-dbg
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	# Force dpkg-deb to use gzip compression so that bintray won't complain about the
	# Ubuntu Bionic debian package being malformed.
	dh_builddeb -a -- -Zgzip

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean install build

